#pragma once #define _USE_MATH_DEFINES #include namespace KrzyweLissajous { ... ... ... #pragma endregion double Ax,Ay,Wx,Wy,F; static double Xp=-1.1, Xk=1.1, Yp=-1.1, Yk=1.1; int ex( double x) { return int((x-Xp)/(Xk-Xp)*pictureBox1->Width); } int ey( double y) { return int((Yk-y)/(Yk-Yp)*pictureBox1->Height); } double rzx( double x) { return Xp+(Xk-Xp)*x/pictureBox1->Width; } double rzy( double y) { return Yk-(Yk-Yp)*y/pictureBox1->Height; } // ------------------------------------------------------------------------- private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { Ax=1.0; Ay=1.0; Wx=1.0; Wy=3.0; F=0.0; panel2->BackColor=Color::Blue; } // ------------------------------------------------------------------------- private: System::Void hScrollBar_Scroll(System::Object^ sender, System::Windows::Forms::ScrollEventArgs^ e) { Ax=0.01*hScrollBarAx->Value; Ay=0.01*hScrollBarAy->Value; Wx=0.1*hScrollBarWx->Value; Wy=0.1*hScrollBarWy->Value; F=hScrollBarF->Value*M_PI/180.0; labelAx->Text=L"Ax = "+Ax.ToString("F2"); labelAy->Text=L"Ay = "+Ay.ToString("F2"); labelWx->Text=L"Wx = "+Wx.ToString("F1"); labelWy->Text=L"Wy = "+Wy.ToString("F1"); labelF->Text=L"fi = "+(F*180/M_PI).ToString("F0"); pictureBox1->Invalidate(); } // ------------------------------------------------------------------------- private: System::Void pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { Graphics^ grafika = e->Graphics; grafika->Clear( Color::White); //colorDialog2->Color); Pen^ pioro=gcnew Pen(System::Drawing::Color::Black); pioro->EndCap=Drawing2D::LineCap::ArrowAnchor; grafika->DrawLine(pioro, ex(Xp),ey(0.0),ex(Xk),ey(0.0)); grafika->DrawLine(pioro, ex(0.0),ey(Yp),ex(0.0),ey(Yk)); pioro->EndCap=Drawing2D::LineCap::NoAnchor; pioro->Color=panel2->BackColor; pioro->Width=int(numericUpDown1->Value); //pioro->Width=2; double xp,yp,xk=Ax*sin(0.0),yk=Ay*cos(0.0+F),dt=0.05; for(double t=0; t<10; t+=dt) { xp=xk; yp=yk; xk=Ax*sin(Wx*(t+dt)); yk=Ay*cos(Wy*(t+dt)+F); grafika->DrawLine(pioro, ex(xp),ey(yp), ex(xk),ey(yk)); } } // ------------------------------------------------------------------------- private: System::Void pictureBox1_Resize(System::Object^ sender, System::EventArgs^ e) { pictureBox1->Invalidate(); } // ------------------------------------------------------------------------- private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { } // ------------------------------------------------------------------------- private: System::Void pictureBox1_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { int xe=e->X,ye=e->Y; double xr=rzx( xe),yr=rzy( ye); tLabelEkr->Text=L"(x,y)ekr = ("+xe.ToString()+L"; "+ye.ToString()+L")"; tLabelRzecz->Text=L"(x,y)rzecz = ("+xr.ToString("F2")+L"; "+yr.ToString("F2")+L")"; } // ------------------------------------------------------------------------- private: System::Void checkBox1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { timer1->Enabled=checkBox1->Checked; } // ------------------------------------------------------------------------- private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) { //static int a=0; a++; //label1->Text=L"a = "+a.ToString(); hScrollBarF->Value=(hScrollBarF->Value+3)%hScrollBarF->Maximum; F=hScrollBarF->Value*M_PI/180.0; labelF->Text=L"fi = "+(F*180/M_PI).ToString("F0"); pictureBox1->Invalidate(); } // ------------------------------------------------------------------------- private: System::Void panel2_Click(System::Object^ sender, System::EventArgs^ e) { if(colorDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK) panel2->BackColor = colorDialog1->Color; pictureBox1->Invalidate(); } // ------------------------------------------------------------------------- }; }